//
//  DesDetailPlaceTableViewCell.m
//  HappyTrip
//
//  Created by yuxuesong on 15-3-26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DesDetailPlaceTableViewCell.h"

@interface DesDetailPlaceTableViewCell()

@property (nonatomic, retain)UIImageView *picImageView;
@property (nonatomic, retain)UIImageView *titlePic;
@property (nonatomic, retain)UILabel *nameLabel;
@property (nonatomic, retain)UIImageView *visited_wishPic;
@property (nonatomic, retain)UILabel *visited_wishLabel;
@property (nonatomic, retain)UIImageView *addressPic;
@property (nonatomic, retain)UILabel *addressLabel;

@end

@implementation DesDetailPlaceTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.picImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.picImageView];
        [_picImageView release];
        
        self.titlePic = [[UIImageView alloc] init];
        [self.picImageView addSubview:_titlePic];
        [_titlePic release];
        
        self.nameLabel = [[UILabel alloc] init];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.textColor = [UIColor whiteColor];
        [self.picImageView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.visited_wishPic = [[UIImageView alloc] init];
        [self.picImageView addSubview:_visited_wishPic];
        [_visited_wishPic release];
        
        self.visited_wishLabel = [[UILabel alloc] init];
        _visited_wishLabel.textAlignment = NSTextAlignmentLeft;
        _visited_wishLabel.textColor = [UIColor whiteColor];
        [self.picImageView addSubview:_visited_wishLabel];
        [_visited_wishLabel release];
        
        self.addressPic = [[UIImageView alloc] init];
        [self.picImageView addSubview:_addressPic];
        [_addressPic release];
        
        self.addressLabel = [[UILabel alloc] init];
//        _addressLabel.textAlignment = NSTextAlignmentRight;
        _addressLabel.textColor = [UIColor whiteColor];
        [self.picImageView addSubview:_addressLabel];
        [_addressLabel release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.bounds.size.width;
    CGFloat heigth = self.bounds.size.height;
    
    _picImageView.frame = CGRectMake(10, 3, width - 20, heigth - 6);
    _picImageView.layer.cornerRadius = width / 30;
    _picImageView.contentMode = UIViewContentModeScaleAspectFill;
    _picImageView.clipsToBounds = YES;
    
    _titlePic.frame = CGRectMake(10, 10 + _picImageView.frame.size.height / 7 / 2 - 6, 12, 12);
    _nameLabel.frame = CGRectMake(25, 10, _picImageView.frame.size.width - 2 * 25, _picImageView.frame.size.height / 7);
    _nameLabel.text = self.placeDetailObject.name;
    
    _visited_wishPic.frame = CGRectMake(10, 10 + _picImageView.frame.size.height / 7 + (_picImageView.frame.size.height / 7) / 2 - 6, 12, 12);
    _visited_wishLabel.font = [UIFont systemFontOfSize:12];
    _visited_wishLabel.frame = CGRectMake(25, 10 + _picImageView.frame.size.height / 7,  _picImageView.frame.size.width - 2 * 10, _picImageView.frame.size.height / 7);
    
    _addressPic.frame = CGRectMake(10, (_picImageView.frame.size.height * 6 / 7 - 10) + (self.picImageView.frame.size.height / 7 + 10) / 2 - 6, 12, 12);
    _addressLabel.frame = CGRectMake(25,_picImageView.frame.size.height * 6 / 7 - 10, _picImageView.frame.size.width - 2 * 25, self.picImageView.frame.size.height / 7 + 10);
    _addressLabel.font = [UIFont systemFontOfSize:12];
    _addressLabel.numberOfLines = 0;
    
    _titlePic.image = [UIImage imageNamed:@"iconfont-bourn2.png"];
    _visited_wishPic.image = [UIImage imageNamed:@"iconfont-qulvxing.png"];
    _visited_wishLabel.text = [[[[self.placeDetailObject.visited_count stringValue] stringByAppendingString:@" 人去过 / "] stringByAppendingString:[self.placeDetailObject.wish_to_go_count stringValue]] stringByAppendingString:@" 人喜欢"];
    _addressPic.image = [UIImage imageNamed:@"address.png"];
    _addressLabel.text = self.placeDetailObject.address;
    [self.picImageView setImageWithURL:[NSURL URLWithString:_placeDetailObject.cover] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}

- (void)dealloc
{
    [_placeDetailObject release];
    [_picImageView release];
    [_titlePic release];
    [_nameLabel release];
    [_visited_wishPic release];
    [_visited_wishLabel release];
    [_addressPic release];
    [_addressLabel release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
